package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ErrorCode;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.OverflowList;
import com.atguigu.jxc.entity.OverflowListGoods;
import com.atguigu.jxc.service.OverflowListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("overflowListGoods")
public class OverflowListGoodsController {

    @Autowired
    private OverflowListGoodsService overflowListGoodsService;

    /**
     * 保存商品报溢单
     * @param overflowList
     * @param overflowListGoodsStr
     * @param request
     * @return
     */
    @PostMapping("save")
    public ServiceVO save(OverflowList overflowList, String overflowListGoodsStr, HttpServletRequest request){
        String overflowNumber = request.getParameter("overflowNumber");
        Boolean flag = overflowListGoodsService.save(overflowList,overflowListGoodsStr,overflowNumber);
        if (flag){
            return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
        }
        return new ServiceVO(ErrorCode.NAME_PASSWORD_ERROR_CODE,ErrorCode.REQ_ERROR_MESS);
    }

    /**
     * 查询报溢单列表
     * @param sTime
     * @param eTime
     * @return
     */
    @PostMapping("list")
    public Map<String,Object> list(String  sTime, String  eTime){
        HashMap<String, Object> map = new HashMap<>();
        List<OverflowList> list = overflowListGoodsService.getList(sTime,eTime);
        map.put("rows",list);
        return map;

    }

    /**
     * 查询报溢单下的商品集合
     * @param overflowListId
     * @return
     */
    @PostMapping("goodsList")
    public Map<String,Object> goodsList(Integer overflowListId){
        List <OverflowListGoods> list = overflowListGoodsService.getGoodsList(overflowListId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("rows",list);
        return map;
    }
}
